
<%@ page import="java.util.List" %>
<%@ page import="domain.model.group.Group" %>
<%@ page import="domain.model.user.User" %>
<%@ page import="domain.model.user.mapper.UserInputMapper"%>

<h2> ${title} </h2>
<br/>
<div>
	<table id="BrowseGroupTable">
		<tr>
			<th> Group Name </th>
			<th> Description </th>
			<th> &nbsp; </th>
		</tr>
		<%
		
			List<Group> groups = (List<Group>)request.getAttribute("groups");
			List<User> users = (List<User>)request.getAttribute("users");
			for( Group group: groups )
			{
		%>
			<tr>
				<td>
					<a href="" onclick="showTeam(<%=group.getId()%>, this); return false;" > 	&rarr;  &nbsp; <%=group.getName()%></a>
					<div id="group_box_<%=group.getId()%>" style="display: none; text-align:left; padding-left:11px; padding-top:5px;">
						<% for(User u: users)
						   {
								if(u.getGroup().getId() == group.getId())
								{
						%>
								&bull;  &nbsp; <%=u.getFirstName()%> <%=u.getLastName()%><br />
						<% 		} 
						   }
						%>
					</div>
				</td>
				<td> <%=group.getDescription()%> </td>
				
				<% //if your NOT in a group then display the want to join button 
				
				User user = UserInputMapper.find((Long)(request.getSession().getAttribute("userid")));
				if(user.getGroup().getId() == 0) {
				%>
				<td> <a href="" class="button1" onclick="resquestEntry(<%=group.getId()%>); return false;"> I wanna join! </a> </td>
				<%} // end of if%>
			</tr>
		<%
			}
		%>
	</table>
</div>